package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.ClazzOption;
import com.itheima.pojo.JobOption;
import com.itheima.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Author：cxl
 * @Package：com.itheima.service.impl
 * @Project：web-project
 * @name：ReportServiceImpl
 * @Date：2025-09-29 1:26 pm
 * @Filename：ReportServiceImpl
 */
@Service
@Slf4j
public class ReportServiceImpl implements ReportService {
    @Autowired
    EmpMapper empMapper;
    @Autowired
    StudentMapper studentMapper;

    @Override
    public JobOption empJobData() {
        List<Map<String, Object>> list = empMapper.countEmpJobData();
        List<Object> jobList = list.stream().map(map -> map.get("pos")).toList();
        List<Object> dataList = list.stream().map(map -> map.get("total")).toList();
        return new JobOption(jobList, dataList);
    }

    @Override
    public List<Map> empGenderData() {
        return empMapper.countEmpGenderData();
    }

    /*学员学历统计*/
    @Override
    public List<Map> studentDegreeData() {
        return studentMapper.countStudentDegreeData();
    }

    /*学员班级统计*/
    @Override
    public ClazzOption ClazzData() {
        List<Map<String, Object>> list = studentMapper.clazzData();
        log.debug("查询到的班级数据: {}", list); // 添加调试日志
        List<Object> clazzList = list.stream().map(map -> map.get("name")).toList();
        List<Object> dataList = list.stream().map(map -> map.get("value")).toList();
        return new ClazzOption(clazzList, dataList);
    }
}
